package com.rjwh.dingdong.client.mvp.presenter.impl;

import android.content.Context;

import com.aishua.lib.task.AsResult;
import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.impl.MoreFeedBackModel;
import com.rjwh.dingdong.client.mvp.presenter.IMoreFeedBackPresenter;
import com.rjwh.dingdong.client.mvp.view.MoreFeedBackView;
import com.rjwh.dingdong.client.util.ToastUtil;

/**
 * @author Kay
 * @ClassName MoreFeedBackPresenter
 * @Description
 * @date 2016-8-5
 * @history 2016-8-5 author: description:
 */
public class MoreFeedBackPresenter extends BasePresenter<MoreFeedBackView> implements IMoreFeedBackPresenter{

    private MoreFeedBackModel model;

    public MoreFeedBackPresenter(Context context, MoreFeedBackView mMvpView) {
        super(context, mMvpView);
        model = new MoreFeedBackModel(this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if(isViewAttached()){
            getMvpView().dismissLoading();
            switch (businessType) {
                case NetConstant.LEAVEMESSAGE:
                    if (mAsResult.getResultCode() > NetConstant.MSG_CONNECT_SUCCESS) {
                        ToastUtil.showToast(getContext(), "感谢您的反馈!");
                        getMvpView().FinishActivity();
                    } else if (!AsStrUtils.isEmpty(mAsResult.getResultMsg())) {
                        ToastUtil.showToast(getContext(), mAsResult.getResultMsg());
                    }
                    break;

                default:
                    break;
            }
        }
    }

    @Override
    public void detachView() {
        model.detachView();
        detachViews();
    }

    /**
     * 发送反馈
     *
     * @param content 反馈内容
     */
    @Override
    public void doLeaveMessage(String content) {
        if(isViewAttached()){
            getMvpView().showLoading();
        }
        model.doLeaveMessage(content);
    }
}
